﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// MobiLib, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace MobiLibrary
{
    public partial class MobiLib
    {
        //==================================================================================================================================
        public class PalmDOC_header : IMobiHeader
        {
            public bool IsDirty { get; internal set; }// wartosci READ ONLY
            internal MemoryBlock mb;
            public MemoryBlock MB { get { return mb; } }
            //
            public short Compression { get { return Bytes2Short(mb.Buffer, 0); } }
            public short Unused { get { return Bytes2Short(mb.Buffer, 2); } }
            public int TextLength { get { return Bytes2Int(mb.Buffer, 4); } }
            public short RecordCount { get { return Bytes2Short(mb.Buffer, 8); } }
            public short RecordSize { get { return Bytes2Short(mb.Buffer, 10); } }
            public short EncryptionType { get { return Bytes2Short(mb.Buffer, 12); } }
            public short Unknown { get { return Bytes2Short(mb.Buffer, 14); } }
            //
            public PalmDOC_header(byte[] buff)
            {
                lock (olock)
                {
                    IsDirty = false;
                    mb.Buffer = new byte[buff.Length]; Array.Copy(buff, 0, mb.Buffer, 0, buff.Length);
                }
            }
            //
            //
            internal void Store(MemoryBlock MetaBuffer)
            {
                lock (olock)
                {
                    Array.Copy(mb.Buffer, 0, MetaBuffer.Buffer, mb.Offset, mb.Length);
                }
            }
            //
            //
            public override string ToString()
            {
                lock (olock)
                {
                    return "PalmDOC_header:\n" + string.Format("Compression={0},Unused={1},TextLength={2},RecordCount={3},RecordSize={4},EncryptionType={5},Unknown={6}\n", Compression, Unused, TextLength, RecordCount, RecordSize, EncryptionType, Unknown);
                }
            }
            //
            public string Dump()
            {
                lock (olock)
                {
                    return "PalmDOC_header: MB=" + mb.ToString() + "\n" + string.Format("Compression={0},Unused={1},TextLength={2},RecordCount={3},RecordSize={4},EncryptionType={5},Unknown={6}\n", Compression, Unused, TextLength, RecordCount, RecordSize, EncryptionType, Unknown);
                }
            }
        }
        //
        //==================================================================================================================================
        //
    }//class
}//namespace
